package com.sd.struts;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class MyRegModel {
	
	Connection con;
	String result="fail";
	
	public String register(String uname,String upass,String addr,String email){
		try{
			con=getCon();
			PreparedStatement ps=con.prepareStatement("insert into myuser values(?,?,?,?)");
			ps.setString(1, uname);
			ps.setString(2, upass);
			ps.setString(3, addr);
			ps.setString(4, email);
			
			if(ps.executeUpdate()==1)
				result="success";
		}
		catch(Exception e){
			e.printStackTrace();
		}
		finally{
			try{con.close();}
			catch(Exception e){}
		}
		return result;
	}
	
	public Connection getCon(){
		
		try{
			Class.forName("oracle.jdbc.driver.OracleDriver");
			con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","tiger");
			System.out.println("Connection="+con);
		}
		
		catch(Exception e){}
		return con;
	
	}
}
